package com.springboot.mapper;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import com.springboot.model.po.Orders;

@Mapper
public interface OrdersMapper {

	// 主键不插入只是null，开启自增长列，匹配(封装对象的属性和表中的字段)
	@Options(useGeneratedKeys = true, keyProperty = "orderId", keyColumn = "orderId")
	@Insert("insert into orders(userId , businessId , orderDate , orderTotal , daId , orderState , originDaId) values(#{userId} , #{businessId} , #{orderDate} , #{orderTotal},#{daId}, 0 , #{daId})")
	public int saveOrders(Orders orders);

	// 存在一对多和多对一（商家和明细）
	@Select("select * from orders where orderId= #{orderId}")
	public Orders getOrdersById(@Param("orderId")Integer orderId);

	// 存在一对多和多对一（商家和明细）
	@Select("select * from orders where userId= #{userId}")
	public List<Orders> listOrdersByUserId(@Param("userId")String userId);

	@Update("update orders set orderState = #{orderState} where orderId = #{orderId}")
	public int updateOrderState(@Param("orderId")Integer orderId,@Param("orderState") Integer orderState);

	@Update("update orders set orderTotal = #{orderTotal} where orderId = #{orderId}")
	public int setOrderTotal(@Param("orderId")Integer orderId,@Param("orderTotal") BigDecimal orderTotal);
}
